﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;
using GCELibrary.Current;

namespace ZF.WS.UserControls.House
{
    public partial class InfoList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var typeList = DictionaryConfig.IInfoType.Take(8);
            this.lvInfoTitle.DataSource = typeList.Select(p => new
            {
                Key = p.InfoTypeId,
                Text = p.Name,
            });
            this.lvInfoTitle.DataBind();
            this.lvInfoTitle1.DataSource = DictionaryConfig.IInfoType.Select(p => new
            {
                Key = p.InfoTypeId,
                Text = p.Name,
            }).ToList();
            this.lvInfoTitle1.DataBind();


            lvHot.DataSource = typeList.Select(p => new
            {
                Key = p.InfoTypeId,
                Text = p.Name,
            });
            lvHot.DataBind();
            using (var dc = SiteInfo.CreateDBDataContext())
            {



                var cacheKey = "InfoList_DicHoustType";
                Dictionary<object, List<object>> DicHoustType = null;
                var obj = HttpCache.GetCache(cacheKey);
                if (obj != null && obj is Dictionary<object, List<object>>)
                {
                    DicHoustType = (Dictionary<object, List<object>>)obj ;
                }
                else
                {
                    DicHoustType = new Dictionary<object, List<object>>();
                    foreach (var type in typeList)
                    {
                        var list = dc.I_Info.Where(p => p.Status == 1 && p.IsVerify)
                            .Where(p => p.InfoTypeId == type.InfoTypeId)
                            .OrderByDescending(p => p.AddTime).Take(8).ToList().Select(p =>
                             (object)new
                             {
                                 Info = p,
                                 PCtn=HttpUtility.HtmlEncode(p.Content),
                                 City = SiteInfo.Instance.GetAreaOrDefault(p.AreaId1).Name,
                                 Price = p.Price == 0 ? "面议" : p.Price == -1 ? "--" : p.Price.ToString() + "元",
                             }).ToList();
                        DicHoustType[type.InfoTypeId] = list;
                    }

                    SiteInfo.Instance.SetPageCache(cacheKey,DicHoustType);
                }
 
                
                this.lvInfoList.DataSource = DicHoustType;
                this.lvInfoList.DataBind();

                this.lvFitup.DataSource = dc.I_Fitup.Where(p => p.TypeId == 1).OrderByDescending(p => p.AddTime).Take(5).ToList();
                this.lvFitup.DataBind();
            }
            



             
        }



    }
}